<template>
  <div class="modify_container">
    <div class="modify_box">
       <div class="avatar_box">
        <img src="https://gitee.com/xiao-ershi/img/raw/master/60d442bb84376.png" alt="">
      </div>
      <div class="box_2">
      <el-form
        ref="modifyFormRef"
        :model="modifyForm"
        label-width="0px"
        class="modify_form"
        :rules="modifyFormRules"
      >
      <div class="forget_header">
        <h2>修改密码</h2>
      </div>
        <!-- 新密码 -->
        <el-form-item prop="new">

          <el-input
            v-model="modifyForm.new"
            type="password"
            placeholder="请输入新密码"
          ></el-input>
        </el-form-item>
        <!-- 确认密码 -->
        <el-form-item prop="confirm">

          <el-input
            v-model="modifyForm.confirm"
            type="password"
            placeholder="请确认新密码"
          ></el-input>
        </el-form-item>

        <!-- 按钮区域 -->
        <el-form-item class="btn">
          <el-button type="primary"  @click="sureChange">确认修改</el-button>
        </el-form-item>
        <!-- 弹出框 -->
        <el-dialog
         title="确认修改"
         :visible.sync="addDialogVisible"
         width="45%"
         @close="addDialogClosed">
         <!-- 内容区域 -->
        <h2>密码修改成功</h2>
        <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="login">返 回 登 录</el-button>
  </span>
</el-dialog>
      </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      modifyForm: {
        new: "",
        confirm: "",
      },
      addDialogVisible: false,
       modifyFormRules: {
        new: [
          { required: true, message: '请输入新密码', trigger: 'blur' },
          { min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }
        ],
        confirm: [
          { required: true, message: '请确认新密码', trigger: 'blur' },
          { min: 6, max: 15, message: '长度在 6 到 15 个字符', trigger: 'blur' }
        ]
      }
    };
  },

  methods: {
   async sureChange() {
     console.log(this.modifyForm.new);
     console.log(this.modifyForm.confirm);
      if(this.modifyForm.new == this.modifyForm.confirm){
      const {data: res} = await this.$http.post('/api/user/change3',{password:this.modifyForm.new,account:sessionStorage.getItem('account')})
        console.log(res);
        this.addDialogVisible= true
      }else{
        console.log(456);
      }
      // this.$http.post('/api/user/change3',this.)
    },
    login() {
      this.$router.push("/login");
    },
        // 监听添加用户对话框的关闭事件
    addDialogClosed() {
      this.$refs.addFormRef.resetFields()
    },
  },
};
</script>

<style>
.modify_container {
 background: url("https://s3.bmp.ovh/imgs/2021/10/56b6bdc4fa7dc31d.png");
  height: 100%;
}

.modify_box {
  width: 650px;
  height: 370px;
  background-color: #fff;
  border-radius: 3px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.modify_form {
  position: absolute;
  bottom: 0;
  width: 100%;
  padding: 0 40px;
  box-sizing: border-box;
}

.btn {
  display: flex;
  justify-content: center;
}

.avatar_box {
  height: 300px;
  width: 300px;
  position: absolute;
  left: 2%;
  top: 7%;
  background-color: #fff;
}

.avatar_box img {
  position: absolute;
  width: 100%;
  height: 100%;
  background:#fff;
  top: 4%;
}

.box_2 {
  box-sizing: border-box;
  display: flex;
  position: absolute;
 width: 382px;
 height: 390px;
 left: 43%;
}
.box_2 input {
  border-radius: 0%;
  border: none;
  border-bottom: 2px solid dodgerblue;
}
.modify_form {
    position: absolute;
    bottom: 52px;
    width: 100%;
    padding: 0 40px;
    box-sizing: border-box;
}
.forget_header {
    position: absolute;
    left: 37%;
    top: -35%;
    color: dodgerblue;
}
.el-dialog__body {
    padding: 12px 79px;
    color: #606266;
    font-size: 14px;
    word-break: break-all;
}
</style>